<?php
namespace QinglongApp\Playday\Http\Controller;

use Qinglong\Framework\Io\Input;
use Qinglong\Framework\Io\Output;
use Qinglong\Framework\Library\Validator;

class Playday {
    /**
     * 获取调休通知列表
     * @param Output $output
     * @throws \Qinglong\Framework\Exception\CommonException
     */
    public function playday_list(Output $output) {

        //申明变量
        $error = 0;
        $msg = '';
        //输入验证

        //数据处理
        if (!$error) {
            $playday_service = app() -> make(\QinglongApp\Playday\Src\Service\Playday::class);
            $first = $playday_service -> getList();
        }
        //数据输出
        $output['playday_list'] = $first;
    }
    /**
     * 获取调休通知详情
     * @param Input  $input
     * @param Output $output
     * @throws \Qinglong\Framework\Exception\CommonException
     */
    public function playday_detail(Input $input,Output $output) {

        //申明变量
        $error = 0;
        $msg = '';
        $playday_id = $input['playday_plan_id'];

        //输入验证
        $validator = app() -> make(Validator::class);
       // $validator -> validate($input) -> with('playday_plan_id', ['int', '>0']) -> resultTo($error, $msg, $error_input);

        //数据处理
        if (!$error) {
            $playdaydetail_service = app() -> make(\QinglongApp\Playday\Src\Service\Playday::class);
            $first = $playdaydetail_service -> getDetail($playday_id);
        }
        //数据输出
        $output['playday_detail'] = $first;
    }

    /**
     * 后台添加调休通知
     * @param Input  $input
     * @param Output $output
     * @throws \Qinglong\Framework\Exception\CommonException
     */
    public function playday_deliver(Input $input,Output $output){

        //申明变量
        $error = 0;
        $msg = '';
        $playday_info['creator'] = $input['creator_id'];
        $playday_info['content'] = $input['content'];
        $playday_info['start'] = $input['start'];
        $playday_info['end'] = $input['end'];
        $playday_info['deadline'] = $input['deadline'];
        $playday_info['allow_days'] = $input['allow_days'];
        $playday_info['weekly_allow_days'] = $input['weekly_allow_days'];

        $blacklist = explode(",",$input['blacklist']);//禁休日
        foreach($blacklist as $k=>$v){
            $playday_info['blacklist'][]['workday']=$v;
        }
        $interfix = explode(",",$input['interfix']);//区域
        foreach($interfix as $k1=>$v1){
            $test = explode("@",$v1);
            $playday_info['interfix'][$k1]['role_id']=$test[0];
            $playday_info['interfix'][$k1]['parent_part_id']=$test[1];
        }

        //输入验证

        //数据处理
        if (!$error) {
            $playday_deliver_service = app() -> make(\QinglongApp\Playday\Src\Service\Playday::class);
            $first = $playday_deliver_service -> playdayDeliver($playday_info);
        }
        //数据输出
        $output['playday_deliver'] = $first;
    }

    /**
     * 后台修改调休通知
     * @param Input  $input
     * @param Output $output
     * @throws \Qinglong\Framework\Exception\CommonException
     */
    public function playday_edit(Input $input,Output $output){
        //申明变量
        $error = 0;
        $msg = '';
        $playday_info['playday_id'] = (int)$input['playday_id'];
        $playday_info['creator'] = $input['creator_id'];
        $playday_info['content'] = $input['content'];
        $playday_info['start'] = $input['start'];
        $playday_info['end'] = $input['end'];
        $playday_info['deadline'] = $input['deadline'];
        $playday_info['allow_days'] = $input['allow_days'];
        $playday_info['weekly_allow_days'] = $input['weekly_allow_days'];
        $playday_info['edit_type'] = $input['edit_type']?$input['edit_type']:0;

        $blacklist = explode(",",$input['blacklist']);//禁休日
        foreach($blacklist as $k=>$v){
            $playday_info['blacklist'][]['workday']=$v;
        }
        $interfix = explode(",",$input['interfix']);//区域
        foreach($interfix as $k1=>$v1){
            $test = explode("@",$v1);
            $playday_info['interfix'][$k1]['role_id']=$test[0];
            $playday_info['interfix'][$k1]['parent_part_id']=$test[1];
        }

        //输入验证

        //数据处理
        if (!$error) {
            $playday_edit_service = app() -> make(\QinglongApp\Playday\Src\Service\Playday::class);
            $first = $playday_edit_service -> playdayEdit($playday_info);
        }
        //数据输出
        $output['playday_edit'] = $first;
    }

    /**
     * 后台删除调休通知
     * @param Input  $input
     * @param Output $output
     * @throws \Qinglong\Framework\Exception\CommonException
     */
    public function playday_delete(Input $input,Output $output){
        //申明变量
        $error = 0;
        $msg = '';
        $playday_info['playday_id'] = (int)$input['playday_id'];

        //输入验证

        //数据处理
        if (!$error) {
            $playday_delete_service = app() -> make(\QinglongApp\Playday\Src\Service\Playday::class);
            $first = $playday_delete_service -> playdayDel($playday_info);

        }
        //数据输出
        $output['playday_delete'] = $first;
    }

    /*
     * 禁休日列表展示
     *  @param Input  $input
     * @param Output $output
     * @throws \Qinglong\Framework\Exception\CommonException
     */
    public function black_list(Output $output){
        //申明变量
        $error = 0;
        $msg = '';

        //输入验证

        //数据处理
        if (!$error) {
            $blackliste_service = app() -> make(\QinglongApp\Playday\Src\Service\Playday::class);
            $first = $blackliste_service -> getBlacklist();

        }
        //数据输出
        $output['black_list'] = $first;
    }

    /*
     * 禁休日详情展示
     *  @param Input  $input
     * @param Output $output
     * @throws \Qinglong\Framework\Exception\CommonException
     */
    public function black_detail(Input $input,Output $output){
        //申明变量
        $error = 0;
        $msg = '';
        $black_id = $input['black_id'];
        //输入验证

        //数据处理
        if (!$error) {
            $blackdetail_service = app() -> make(\QinglongApp\Playday\Src\Service\Playday::class);
            $first = $blackdetail_service -> getBlackdetail($black_id);
        }
        //数据输出
        $output['playday_detail'] = $first;
    }
}